package com.jade.inventory.service.service.impl;

import com.jade.bss.DbException;
import com.jade.bss.base.utils.CopyBean;
import com.jade.bss.db.impl.BaseFacadeImpl;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.criterion.Restrictions;
import com.jade.framework.base.util.PagingList;
import com.jade.framework.base.util.PagingResult;
import com.jade.zsy.inventory.dao.TransferDao;
import com.jade.zsy.inventory.entity.Transfer;
import com.jade.zsy.inventory.service.TransferFacade;
import com.jade.zsy.inventory.vo.TransferVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * 商品管理
 * User: jinya
 * Date: 2017/5/24
 * Time: 15:41
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
@Service("TransferFacade")
public class TransferFacadeImpl extends BaseFacadeImpl implements TransferFacade {
    @Inject
    @Named("TransferDao")
    private TransferDao entityDao;
    @Override
    @Transactional
    public void save(Object obj) throws DbException {
        Transfer entity=(Transfer)obj;
        entity.setOwnerId("1");
        super.save(entity);
    }

    @Override
    public PagingResult queryEntity(Object entity, int page, int size, String keys, String... orders) throws DbException,IllegalAccessException, InstantiationException {
        TransferVo sku=(TransferVo)entity;
        Criteria criteria = new Criteria((page - 1) * size, size);
        if(StringUtils.isNotEmpty(keys)){
            criteria.add(Restrictions.or(Restrictions.like("skuCode", keys),Restrictions.like("barcode", keys)));
        }

        PagingList pagingList = entityDao.queryEntity(Transfer.class, criteria);
        PagingResult  result = PagingResult.getResult(CopyBean.copy(pagingList, TransferVo.class), pagingList.getTotalCount(), page, size);
        return result;
    }
}